<#--
总页数，当前页
<#import "inc/paging.ftl" as paging >
<@paging.paging totalPages,RequestParameters['p']?default('1')?number;num,text>
    <a href="?p=${num}&s=${sort}" >${text}</a>
</@paging.paging>
-->

<#macro paging _totalPageNum _currentPageNo _maxShowNums=10  >

    <#local curr=_currentPageNo>
    <#local pages=_totalPageNum>
    <#local prev=(curr gt 1)?string((curr-1)?string,'1')?number>
    <#local next=(curr lt pages)?string((curr+1)?string,pages?string)?number>

    <#local _html>

        <#if curr==1>
            <a href="javascrit:void(0);" class="layui-laypage-prev layui-disabled">上一页</a>
        <#else>
            <#nested prev,'上一页'>
        </#if>

        <#if curr gte 6 && pages gt 10>
            <#nested 1,'1'>
            <span class="layui-laypage-spr">…</span>
        </#if>

        <#if pages lte 10>
            <#local a = 1>
            <#local b = pages>
        <#else>
        <#--正常情况下前后显示3个-->
            <#local a = curr - 3>
            <#local b = curr + 3>
        <#--如果距离首尾只差5个就直接显示-->
            <#if curr lte 5>
                <#local a = 1>
                <#local b = 8>
            </#if>
            <#if pages-curr lte 5>
                <#local b = pages>
                <#local a = pages-7>
            </#if>
        </#if>
    <#--控制不要超出范围-->
        <#if a lt 1>
            <#local a = 1>
        </#if>
        <#if b gt pages>
            <#local b = pages>
        </#if>

        <#list a..b as n>
            <#if curr == n>
                <span class="layui-laypage-curr ipage-curr">
                    <em class="layui-laypage-em" style="background-color:#FF5722;"></em>
                    <em>${curr}</em>
                </span>
            <#else>
                <#nested n,n>
            </#if>
        </#list>

        <#if (pages-curr gt 5) && (b lt pages)>
            <span class="layui-laypage-spr">…</span>
            <#nested pages,pages>
        </#if>


        <#if curr==pages>
            <a href="javascrit:void(0);" class="layui-laypage-prev layui-disabled ipage-prev">下一页</a>
        <#else>
            <#nested next,'下一页'>
        </#if>

    </#local>

    <style>
        .ipage{
            display: inline-block;
            *display: inline;
            *zoom: 1;
            vertical-align: middle;
            margin: 10px 0;
            font-size: 0;
        }
        .ipage a{
            display: inline-block;
            *display: inline;
            *zoom: 1;
            vertical-align: middle;
            padding: 0 15px;
            height: 28px;
            line-height: 28px;
            margin: 0 -1px 5px 0;
            background-color: #fff;
            color: #333;
            font-size: 12px;
        }
        .ipage>a:first-child{
            border-radius: 2px 0 0 2px;
        }
        .ipage>:first-child {
            margin-left: 0!important;
        }
        .ipage a {
            text-decoration: none;
            border: 1px solid #eee;
        }

    </style>

    <div class="layui-box layui-laypage layui-laypage-default ipage">
        ${_html}
    </div>

</#macro>